<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	选择要上传的文件：
	<br />

	<form action="ProductServlet" method="post"
		enctype="multipart/form-data">
		真实姓名：<input name="realName" /><br />
		<div id="upImg">
			<input type="file" name="picOne" id="picOne" />
		</div>

		<img src="${pageContext.request.contextPath}/images/df.jpg" height="150px" id="imgShow" /> <input
			type="submit" value="提交" />
	</form>
	<script>
		document.getElementById("picOne").onchange = function() {//当chooseImage的值改变时，执行此函数
			var root="${pageContext.request.contextPath}/";
			var url = root+"images/df.jpg";
			var ext = this.value.substring(this.value.lastIndexOf(".")).toLowerCase();
			if (ext != '.png' && ext != '.jpg' && ext != '.jpeg'&& ext != '.gif') {
				this.value="";
			} else {
				var file = this.files[0];
				url = window.URL.createObjectURL(file); //转成可以在本地预览的图片对象并获取地址
			}
			//显示预览
			document.getElementById("imgShow").setAttribute("src", url);

		}
	</script>
</body>
</html>